/**
 * losenote.com Inc.
 * Copyright (c) 2013-2013 All Rights Reserved.
 */
package com.losenote.model.ct;

import com.losenote.enums.QuestionTypeEnum;
import com.losenote.model.Question;
import com.losenote.orm.QuestionDO;

/**
 * 问题对象转换器
 * 
 * @author danjingyu
 * @version $Id: QuestionConvertor.java, v 0.1 2013-10-26 下午5:12:58 danjingyu Exp $
 */
public class QuestionConvertor {

    /**
     * question对象转换器
     * 
     * @param question
     * @return
     */
    public static QuestionDO fromModel(Question question, int relId) {
        QuestionDO questionDo = new QuestionDO();
        //拷贝属性
        questionDo.setRelId(relId);
        questionDo.setSequence(question.getSequence());
        questionDo.setRelType(Integer.valueOf(question.getQuestionTypeEnum().getValue()));
        questionDo.setQuestion(question.getQuestion());
        questionDo.setAnswer(question.getAnswer());
        return questionDo;
    }

    /**
     * question对象转换器
     * 
     * @param question
     * @return
     */
    public static Question fromDO(QuestionDO questionDO) {
        Question question = new Question();
        //拷贝属性
        question.setId(questionDO.getId());
        question.setSequence(question.getSequence());
        question.setQuestionTypeEnum(QuestionTypeEnum.getByValue(questionDO.getRelType()));
        question.setQuestion(questionDO.getQuestion());
        question.setAnswer(question.getAnswer());
        return question;
    }
}
